/*
 * @Description: 
 * @Author: paddies
 * @Date: 2024-05-09 00:08:27
 * @LastEditors: paddies
 * @LastEditTime: 2025-01-20 18:27:15
 * @FilePath: /shared_components/lib/build-radio/buildRadio.dart
 */
import 'package:flutter/material.dart';
import 'package:shared_components/build-common/buildCommon.dart';

Widget buildRadio(
    {String title = '名称',
    bool required = false,
    FocusNode? focusNode,
    List list = const [],
    String value = "",
    Color activeColor = const Color(0xff0101ec),
    int widthFactor = 2,
    TextEditingController? textEditingController,
    double labelWidth = 90,
    String placeholder = '请填写',
    Function? onChanged}) {
  return Container(
    width: double.infinity,
    // height: 60,
    padding: EdgeInsets.only(left: 10, right: 10),
    // margin: const EdgeInsets.only(left: 15, right: 15),
    decoration: const BoxDecoration(
      border: Border(
          top: BorderSide(width: 1.0, color: Color(0xffF4F4F4)),
          bottom: BorderSide(width: 1.0, color: Color(0xffF4F4F4))),
    ),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Container(
          width: labelWidth,
          alignment: Alignment.centerLeft,
          constraints: BoxConstraints(minHeight: 60.0 // 设置最小高度为100.0
              ),
          // height: double.infinity,
          // color: Colors.green,
          child: Row(
            children: [
              Visibility(
                  visible: required,
                  child: const Padding(
                    padding: EdgeInsets.only(top: 5),
                    child: Text(
                      "*",
                      style: TextStyle(fontSize: 20, color: Colors.red),
                    ),
                  )),
              Text(
                title,
                style: TextStyle(fontSize: 16),
              )
            ],
          ),
        ),
        Expanded(
            flex: 1,
            child: Container(
                width: double.infinity,
                // height: 100,
                // color: Colors.red,
                child: Wrap(
                    spacing: 0, //主轴上子控件的间距
                    runSpacing: 0,
                    children: [
                      ...list.map((e) {
                        return FractionallySizedBox(
                            widthFactor: 1 / widthFactor,
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: [
                                Radio(
                                  // 按钮的值
                                  value: e['value'],
                                  activeColor: activeColor,

                                  // 改变事件
                                  onChanged: (value) {
                                    if (onChanged != null) {
                                      onChanged(value);
                                    }
                                  },
                                  // 按钮组的值
                                  groupValue: value,
                                ),
                                Expanded(
                                    child: GestureDetector(
                                        onTap: () {
                                          if (onChanged != null) {
                                            onChanged(e["value"]);
                                          }
                                        },
                                        child: Text(
                                          showText(
                                            e["label"],
                                          ),
                                          style: TextStyle(fontSize: 16),
                                          overflow: TextOverflow.ellipsis,
                                        ))),
                              ],
                            ));
                      }).toList(),
                    ])))
      ],
    ),
  );
}
